package com.study.service.impl;

import com.study.dao.UserDao;
import com.study.pojo.User;
import com.study.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;
    @Override
    public int deleteByPrimaryKey(int id) {
        return userDao.deleteByPrimaryKey(id);
    }

    @Override
    public int save(User user) {
        int result;
        if(user.getId()!=null && user.getId()>0){
            result = userDao.updateByPrimaryKeySelective(user);
        }else {
            result=userDao.insertSelective(user);
        }
        return result;
    }

    @Override
    public User selectByPrimaryKey(int id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Override
    public User selectByOpenId(String openId) {
        return userDao.selectByOpenId(openId);
    }

    @Override
    public List<User> selectForList(Map<String, Object> conditions) {
        return userDao.selectForList(conditions);
    }

    @Override
    public boolean dataExist(Map<String, Object> conditions) {
        List<User> userList=userDao.selectForList(conditions);
        return userList!=null&&userList.size()>0;
    }
}
